home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / Animated Cursor / AnimatedCursor.p
Text File  |  1991-01-17  |  1KB  |  63 lines

  1. unit AnimatedCursor;
  2.  
  3. interface
  4.  
  5.     type
  6.         acurState = record
  7.                 which_acur, nextFrame: INTEGER;
  8.                 nextTime: LONGINT;
  9.             end;
  10.  
  11.     procedure Init_acur (theID: INTEGER; var theVars: acurState);
  12.     procedure Animate_acur (var theVars: acurState);
  13.  
  14. implementation
  15.  
  16.     procedure Init_acur (theID: INTEGER; var theVars: acurState);
  17.     begin
  18.         with theVars do
  19.             begin
  20.                 which_acur := theID;
  21.                 nextFrame := 1;
  22.                 nextTime := TickCount;
  23.             end;
  24.     end; { Init_acur }
  25.  
  26.     procedure Animate_acur (var theVars: acurState);
  27.         const
  28.             minTicks = 2;    {Never change frames faster than this}
  29.         type
  30.             acur = record
  31.                     frames, ticks: INTEGER;
  32.                     CURS_ids: array[1..1] of record
  33.                             num, fill: INTEGER
  34.                         end;
  35.                 end;
  36.             acurPtr = ^acur;
  37.             acurHandle = ^acurPtr;
  38.         var
  39.             the_acur: acurHandle;
  40.     begin
  41.         with theVars do
  42.             begin
  43.                 the_acur := acurHandle(GetResource('acur', which_acur));
  44.                 if TickCount >= nextTime then
  45.                     with the_acur^^ do
  46.                         begin
  47.                             HLock(Handle(the_acur));
  48.                             if (nextFrame < 1) or (nextFrame > frames) then
  49.                                 nextFrame := 1;
  50.                             {$PUSH}
  51.                             {$R-}
  52.                             SetCursor(GetCursor(CURS_ids[nextFrame].num)^^);
  53.                             {$POP}
  54.                             nextFrame := nextFrame + 1;
  55.                             nextTime := nextTime + ticks;
  56.                             if TickCount >= nextTime then    {We're playing catch-up, or the acur resource is "hyperkinetic"}
  57.                                 nextTime := TickCount + 2;
  58.                             HUnlock(Handle(the_acur));
  59.                         end;
  60.             end;
  61.     end; { Animate_acur }
  62.  
  63. end.